import numpy as np
import cv2
import glob
import os

path = r'E:\dataset\AIC20_track4_pre\train-data\ori_images\11'
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3))
fgbg = cv2.createBackgroundSubtractorMOG2()
path_file_number = glob.glob(os.path.join(path, '*.jpg'))
for i in range(1, 4):
    part_path = os.path.join(path, str(i))
    if not os.path.exists(part_path):
        os.mkdir(part_path)
frame = cv2.imread(path_file_number[0])
im_w = 800
im_h = 410
scale = [1.0 / 6, 2.0 / 6, 3.0 / 6]
for img in path_file_number:
    frame = cv2.imread(img)
    frame1 = frame[:int(im_h * scale[0]), :, :]
    frame1 = cv2.resize(frame1,
                        (int(im_w * (scale[2] / scale[0])), int(im_h * scale[0] * (scale[2] / scale[0]))))
    frame2 = frame[int(im_h * scale[0]):int(im_h * scale[0] + im_h * scale[1]), :, :]
    frame2 = cv2.resize(frame2, (int(im_w * (scale[2] / scale[1])), int(im_h * scale[1] * (scale[2] / scale[1]))))
    frame3 = frame[int(im_h * scale[0] + im_h * scale[1]):, :, :]
    cv2.imwrite(os.path.join(path, "1", os.path.basename(img)), frame1)
    cv2.imwrite(os.path.join(path, "2", os.path.basename(img)), frame2)
    cv2.imwrite(os.path.join(path, "3", os.path.basename(img)), frame3)